package com.ruoyi.project.admin.personmanager.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.admin.personmanager.domain.Person;
import com.ruoyi.project.admin.personmanager.mapper.PersonMapper;
import com.ruoyi.project.cms.commons.CMSConst;
import com.ruoyi.project.cms.type.domain.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonServiceImpl implements IPersonService {
    @Autowired
    private PersonMapper personMapper;
    @Override
    public List<Person> selectPersonList(Person person) {
        List<Person> personList= personMapper.selectPersonList(person);
        return personList;
    }

    @Override
    public String checkPersonNameUnique(Person person) {
        // 当前可能是在修改公告类型，也可能在新增公告类型。 如果是修改，则需要判定主键。
        Long PersonId = StringUtils.isNull(person.getPersonId()) ? -1L : person.getPersonId();
        Type info = personMapper.checkPersonNameUnique(person.getPersonName());
        if (StringUtils.isNotNull(info) && info.getTypeId().longValue() != PersonId.longValue())
        {
            return CMSConst.TYPE_NAME_NOT_UNIQUE;
        }
        return CMSConst.TYPE_NAME_UNIQUE;

    }

    @Override
    public int insertPerson(Person person) {
      int i=  personMapper.insertPerson(person);
        return i;
    }
}
